#include <stdio.h>
int main()
{

	int arr[8] = {1, 2, 3, 4, 5, 6, 7, 8};

	int m = 0, i = 0, tmp = 0;

	for (i = 0; i < 8; i++)
	{
		printf("%d ", arr[i]);
	}
	scanf("%d", &m);
	for (i = 0; i < m; i++)
	{
		tmp = arr[i];
		arr[i] = arr[8 - m + i];
		arr[8 - m + i] = tmp;
	}
	for (i = 0; i < 8; i++)
	{
		printf("%d ", arr[i]);
	}
}
